#include "misc.h"
#include <QDateTime>

Misc::Misc()
{

}

/**
 * @brief getTimeStamp 获取系统开机到显示的时间戳，单位是ms
 * @return 时间戳
 */
int64_t Misc::getTimeStamp()
{
#ifndef WIN32
    struct timespec ts;
    clock_gettime(CLOCK_MONOTONIC, &ts);
    return  ts.tv_sec * Q_INT64_C(1000) + ts.tv_nsec / Q_INT64_C(1000000);
#else
    return QDateTime::currentMSecsSinceEpoch();
#endif
}

uint32_t Misc::toSecond(uint16_t hour, uint16_t minute, uint16_t second)
{
    uint32_t tmp = second;
    tmp += minute * 60;
    tmp += hour * 3600;
    return tmp;
}

void Misc::toHourMinuteSecond(uint32_t totalSecond, uint16_t *hour, uint16_t *minute, uint16_t *second)
{
    *hour  = totalSecond / 3600;
    totalSecond %= 3600;
    *minute = totalSecond / 60;
    *second = totalSecond % 60;
}
